﻿using UnityEngine;
using System.Collections;

public class PlaySoundEffect : MonoBehaviour
{
    public AudioSource Source;

    // Use this for initialization
    void Start()
    {
        if (Source == null)
        {
            Source = GetComponent<AudioSource>();
        }
    }

    public void PlaySound(string name)
    {
        if (Source == null)
        {
            return;
        }
        // var clip = AuSource.GetComponent<AudioClip>();
        var path = string.Format("Audios/Clips/{0}", name);
        var clip = Resources.Load<AudioClip>(path);
        if (clip == null)
        {
            Debug.LogErrorFormat("clip:{0} is null", path);
            return;
        }
        Source.clip = clip;
        Source.minDistance = 1.0f;

        Source.maxDistance = 50;

        Source.rolloffMode = AudioRolloffMode.Linear;
        Source.Play();
    }
}
